package com.fengye.algorithms.leecode;

import com.fengye.algorithms.leecode.common.ListNode;

/**
 * @Author fengye
 * @Date 2023/4/8 11:48
 **/
public class ReverseList206 {
    public ListNode reverseList(ListNode head) {
        if(head == null) {
            return head;
        }

        ListNode prev = head;
        ListNode next = head.next;
        ListNode curr = next;
        while (next != null) {
            next = next.next;
            curr.next = prev;
            prev = curr;
            curr = next;
        }
        head.next = null;
        return prev;
    }
}
